// ignore_for_file: file_names

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;

class HomePage extends StatefulWidget {
  HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<Map> imgList = [
    {
      "url":
          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zx123.cn%2FResources%2Fzx123cn%2Fuploadfile%2F2016%2F1110%2F3623c1091d9530a0e9f322ab11a7d07b.jpg&refer=http%3A%2F%2Fimg.zx123.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648806126&t=8e2c07128a4ee8b9251c9f98eff7f193"
    },
    {
      "url":
          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20170910%2F3e5c10d7052643ab9382f4e701579ccb.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1649325782&t=33adb3762394b5f42b77282c2d58f407"
    },
    {
      "url":
          "https://bkimg.cdn.bcebos.com/pic/9e3df8dcd100baa1d233d02b4410b912c8fc2e06?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U4MA==,g_7,xp_5,yp_5/format,f_auto"
    }
  ];

  @override
  void initState() {
    super.initState();
  }

  _getData() async {
    // android 模拟器中访问 127.0.0.1 ，换为：10.0.2.2
    var apiUrl = Uri.parse('http://10.0.2.2:7001/');
    var response = await http.get(apiUrl);
    print("Response status: ${response.statusCode}");
    print("Response body: ${response.body}");

    // var apiUrl = Uri.http('https://jd.itying.com', '/api/httpGet');
    // var apiUrl =
    //     Uri.https('www.googleapis.com', '/books/v1/volumes', {'q': '{http}'});
    // var response = await http.get(apiUrl);
    // if (response.statusCode == 200) {
    //   var jsonResponse =
    //       // convert.jsonDecode(response.body) as Map<String, dynamic>;
    //       json.decode(response.body) as Map<String, dynamic>;
    //   var itemCount = jsonResponse['totalItems'];
    //   print('Number of books about http: $itemCount.');
    // } else {
    //   print('Request failed with status: ${response.statusCode}.');
    // }
  }

  _postData() async {}

  @override
  Widget build(BuildContext context) {
    return Column(
      // crossAxisAlignment: CrossAxisAlignment.end,
      // mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Container(
          margin: const EdgeInsets.all(10),
          decoration: new BoxDecoration(
            //设置四周圆角 角度
            borderRadius: BorderRadius.all(Radius.circular(4.0)),
          ),
          width: 500,
          height: 200,
          child: new Swiper(
            itemBuilder: (BuildContext context, int index) {
              return Container(
                  width: 300,
                  child: AspectRatio(
                      aspectRatio: 4.0 / 3.0,
                      child: Image.network(
                        imgList[index]["url"],
                        fit: BoxFit.cover,
                      )));
            },
            itemCount: imgList.length,
            pagination: new SwiperPagination(),
          ),
        ),
        Container(
          margin: const EdgeInsets.all(50),
          child: ElevatedButton(
            child: Text("跳转到检测"),
            onPressed: () {
              Navigator.pushNamed(context, '/inputcase1');
            },
            style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(Colors.blue),
            ),
          ),
        ),
      ],
    );
  }
}
